<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>导航栏选中后高亮显示效果</title>
    <style>
        ul {
            list-style-type: none;
            display: flex;
        }

        ul > li {
            width: 180px;
            display: block;
            text-align: center;
            border: black 1px solid;

            background-color: bisque;
        }

        ul >li >a {
            color: brown;
            text-decoration: none;
        }

        .active{
            color: white;
            background-color: aqua;
        }
        li:hover{
            background-color: blue;
        }
    </style>
</head>
<body>
<div id="app">
    <ul>
        <li v-for="(content, index) in contents" v-on:click="itemClicked(index)" v-bind:class="{active: currentIndex === index}"><a href="https://www.baidu.com">{{ content }}</a></li>
    </ul>
</div>
<script src="../../../../../js/vue.global.js"></script>
<script>
    const app = Vue.createApp({
        data() {
            return {
                contents: ["首页", "CSS 动画", "JavaScript 动画", "Servlet 代码", "Spring 代码"],
                currentIndex:null,
            }
        },
        methods: {
            itemClicked(index){
                this.currentIndex = index
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>